package com.example.howard.xiao7music.ui.adapter.LocalAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.howard.xiao7music.R;

import java.util.List;
import java.util.Map;

/**
 * Created by Howard on 2016/10/1.
 */
public class LocalAllSongAdapter extends BaseAdapter{

    LayoutInflater inflater;
    List<Map<String, Object>> list;
    LocalMainCallback callback;

    public LocalAllSongAdapter(Context c, List<Map<String, Object>> songlist, LocalMainCallback callback) {
        this.inflater = LayoutInflater.from(c);
        this.list=songlist;
        this.callback=callback;
    }

    public int getCount() {
        return list.size();
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    public View getView(final int position, View convertView,
                        ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.local_all_song_item, null);
            viewHolder = new ViewHolder();
//                viewHolder.isplay = (ImageView) convertView
//                        .findViewById(R.id.isplay);
            viewHolder.song_name = (TextView) convertView
                    .findViewById(R.id.song_name);
            viewHolder.siner_name = (TextView) convertView
                    .findViewById(R.id.singer_name);
            viewHolder.listview_click = (TextView) convertView
                    .findViewById(R.id.songlist_click);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.song_name.setText(list.get(position).get("SONG")
                .toString());
        viewHolder.siner_name.setText(list.get(position).get("SINGER")
                .toString());

//            viewHolder.isplay
//                    .setBackgroundResource(R.drawable.play_list_played);

        viewHolder.listview_click.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {
//                dialog(position);
                callback.delete(position);

            }
        });
        return convertView;
    }

    class ViewHolder {
        ImageView isplay;
        TextView song_name, listview_click;
        TextView siner_name;

    }

    public interface LocalMainCallback {

        void delete (int position);
    }

//    protected void dialog(final int position) {
//        AlertDialog.Builder builder = new AlertDialog.Builder(this);
//        builder.setMessage("确认在列表中删除吗？");
//
//        builder.setTitle("不会删除本地歌曲");
//
//        builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
//
//            @Override
//            public void onClick(DialogInterface dialog, int which) {
//                dialog.dismiss();
//
//            }
//        });
//
//        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
//
//            @Override
//            public void onClick(DialogInterface dialog, int which) {
//                dialog.dismiss();
//            }
//        });
//
//        builder.create().show();
//    }
}
